import loadable from '@loadable/component'
import {loadQuery, } from "react-relay/hooks";
import {Environment} from "relay-runtime";
import  HeadlinesMainQuery  from "./__generated__/HeadlinesMainQuery.graphql";
import queryString from "query-string";

export default function secondRouter(environment: Environment) {
  return (
      [
          {
              path: '/aide/Headlines',
              component: loadable(() => import('./HeadlinesMain')),
              prepare: (params:any) => {
                  const qs= queryString.parse(window.location.search);
                  const filt= JSON.parse(localStorage['头条频道']??'{}');
                  const filted=Reflect.ownKeys(filt).length === 0? {chn: ['sei']} : filt;
                  let vars={
                      where: {...filted}, after:null, first:5,orderBy:'crDate',asc:false, twhere: {},
                  };
                  console.log("路由loadQuery前面Headlinesfilter=", { ...filted});
                  return {
                      myQuery: loadQuery(
                          environment as any,
                          HeadlinesMainQuery as any,
                          vars,
                          { fetchPolicy: 'network-only' },
                      ),
                      filter : {where: {...filted}, offset:0, first:5, asc:false }
                  };
              },


          },

      ]

  );
}

